<template>
  <nav>
    <article @click="goToCity">{{ cityname }}</article>
    <ul>
      <li
        v-for="item in navList"
        :key="item.url"
        :class="{ active: item.title === active }"
        @click="tab(item)"
      >
        {{ item.title }}
      </li>
    </ul>
    <span class="iconfont icon-sousuo"></span>
  </nav>
</template>

<script>
export default {
  data() {
    return {
      // navList: ["热映", "影院", "待映", "经典电影"],
      navList: [
        {
          title: "热映",
          url: "/hot",
        },
        {
          title: "影院",
          url: "/cinema",
        },
        {
          title: "待映",
          url: "/wait",
        },
        {
          title: "经典电影",
          url: "/classic",
        },
      ],
      active: "热映",
    };
  },
  computed: {
    cityname() {
      return this.$store.state.city.cityname;
    },
  },
  methods: {
    goToCity() {
      this.$router.push("/city");
    },
    tab(item) {
      this.active = item.title;
      this.$router.push("/home/movies" + item.url);
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../assets/css/var.less";
nav {
  width: 100%;
  height: 45px;
  border-bottom: 1px solid @border-color;
  background: #fff;
  display: flex;

  article {
    width: 62px;
    height: 100%;
    font-size: @s-font;
    .center();
  }

  ul {
    flex: 1;
    display: flex;
    font-size: @s-font;
    margin: 0 20px;

    li {
      flex: 2;
      .center();
    }

    li:last-child {
      flex: 3;
    }

    .active {
      font-size: @m-font;
      font-weight: 900;
      position: relative;

      &::after {
        content: "";
        position: absolute;
        width: 20px;
        height: 4px;
        background: @theme-color;
        border-radius: 2px;
        bottom: 2px;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }

  span {
    width: 45px;
    .center();
    color: @theme-color;
  }
}
</style>
